package com.itheima.web.service.impl.sms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.service.sms.RecommendProductService;
import com.itheima.vo.sms.RecommendProduct;
import com.itheima.web.mapper.sms.RecommendProductMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import java.util.List;

@DubboService
public class RecommendProductServiceImpl extends ServiceImpl<RecommendProductMapper, RecommendProduct> implements RecommendProductService {
    @Override
    public Page<RecommendProduct> getPage(Integer pageNum, Integer pageSize, String productName, Integer recommendStatus) {
        Page<RecommendProduct> page=new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<RecommendProduct> rplqw =new LambdaQueryWrapper<>();
        rplqw.like(Strings.isNotEmpty(productName),RecommendProduct::getProductName,productName);
        rplqw.eq(recommendStatus!=null,RecommendProduct::getRecommendStatus,recommendStatus);
        this.page(page, rplqw);
        return page;
    }

    @Override
    public void updateByStatus(List<Integer> ids, Integer recommendStatus) {
        List<RecommendProduct> recommendProducts = this.listByIds(ids);
        for (RecommendProduct recommendProduct : recommendProducts) {
            recommendProduct.setRecommendStatus(recommendStatus);
        }

        this.updateBatchById(recommendProducts);
    }
}
